package com.example.s.fragment.main_child_fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.s.R;
import com.example.s.adapter.InnerHolder;
import com.example.s.adapter.MyRecyclerViewAdapter;
import com.example.s.bean.FollowerContent;
import com.example.s.fragment.BaseFragment;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.listener.OnPageChangeListener;

import java.util.ArrayList;
import java.util.List;

public class NearbyFragment extends BaseFragment {
    private Banner banner;
    private ImageView range;
    private RecyclerView rvNearby;
    private List<Integer> mBannerDataList = new ArrayList<>();
    private MyRecyclerViewAdapter<FollowerContent> mNearbyContentMyRecyclerViewAdapter;
    private List<FollowerContent> mNeaybyContentList = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.fragment_nearby;
    }

    @Override
    public void initView(View view) {

        banner = (Banner) findViewById(R.id.banner);
        range = (ImageView) findViewById(R.id.range);
        rvNearby = (RecyclerView) findViewById(R.id.rv_nearby);
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mBannerDataList.add(R.drawable.yywlb8);
        mBannerDataList.add(R.drawable.yywlb9);
        mBannerDataList.add(R.drawable.yywlb7);
        mBannerDataList.add(R.drawable.yywlb8);
        banner.setAdapter(new BannerImageAdapter<Integer>(mBannerDataList) {
            @Override
            public void onBindView(BannerImageHolder holder, Integer data, int position, int size) {
                holder.imageView.setBackgroundResource(data);
            }
        })
                .addBannerLifecycleObserver(getActivity())
                .setIndicator(new CircleIndicator(getContext()))
                .setLoopTime(5000);


        rvNearby.setLayoutManager(new LinearLayoutManager(getContext()));
        rvNearby.setAdapter(mNearbyContentMyRecyclerViewAdapter = new MyRecyclerViewAdapter<FollowerContent>(mNeaybyContentList, R.layout.follow_recycler_follwercontent_item) {
            @Override
            public void handleData(InnerHolder holder, FollowerContent item) {

                holder.setSrcResource(R.id.headphoto, item.getHeadphoto());
                holder.setText(R.id.name, item.getName());
                holder.setText(R.id.realseTime, item.getReleaseTime());
                holder.setText(R.id.likes, String.valueOf(item.getLikes()));
                holder.setText(R.id.title, item.getTitle());
                holder.setText(R.id.content, item.getContent());
                holder.setText(R.id.contentNums, 1 + "/" + item.getContentPhotoList().size());
                holder.setText(R.id.email, item.getEmail());
                Banner banner = holder.getView(R.id.contentBanner);
                Log.d(TAG, "handleData: "+mNeaybyContentList.size());
                banner.setAdapter(new BannerImageAdapter<Integer>(item.getContentPhotoList()) {
                    @Override
                    public void onBindView(BannerImageHolder holder, Integer data, int position, int size) {
                        holder.imageView.setImageResource(data);
                    }
                })
                        .addOnPageChangeListener(new OnPageChangeListener() {
                            @Override
                            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                                holder.setText(R.id.contentNums, position + 1 + "/" + item.getContentPhotoList().size());
                            }

                            @Override
                            public void onPageSelected(int position) {

                            }

                            @Override
                            public void onPageScrollStateChanged(int state) {

                            }
                        }).addBannerLifecycleObserver(getActivity());


//                headphoto = (CircleImageView) findViewById(R.id.headphoto);
//                name = (TextView) findViewById(R.id.name);
//                realseTime = (TextView) findViewById(R.id.realseTime);
//                contact = (ImageView) findViewById(R.id.contact);
//                share = (ImageView) findViewById(R.id.share);
//                contentBanner = (Banner) findViewById(R.id.contentBanner);
//                contentNums = (TextView) findViewById(R.id.contentNums);
//                like = (ImageView) findViewById(R.id.like);
//                likes = (TextView) findViewById(R.id.likes);
//                collection = (ImageView) findViewById(R.id.collection);
//                chat = (ImageView) findViewById(R.id.chat);
//                title = (TextView) findViewById(R.id.title);
//                content = (TextView) findViewById(R.id.content);

            }

        });
        setNearByData();
    }


    private void setNearByData() {
        List<Integer> contentDataList = new ArrayList<>();
        contentDataList.add(R.mipmap.home_page_bg);
        contentDataList.add(R.mipmap.home_page_bg);
        contentDataList.add(R.mipmap.home_page_bg);
        List<Integer> contentDataList2 = new ArrayList<>();
       contentDataList2.add(R.mipmap.home_page_bg);
       contentDataList2.add(R.mipmap.home_page_bg);
       contentDataList2.add(R.mipmap.home_page_bg);
        FollowerContent followerContent = new FollowerContent(R.mipmap.home_page_headphoto, "四川邮电", "20分钟前", 103, "客服敏感，树立自信", "当代青年总是有着很多烦恼，很多困扰。但通常这一切的起源还是幻想太多自己该阶段不该幻想的东西，过于敏感给自身带来过多的压力，并总是质疑自己，羡慕别人，渐渐的也就失去了自信。当代青年作为祖国未来的栋梁，这样下去不仅耽误了自己，也一定程度上影响了祖国的发展。若能克服敏感，树立自信，才能拥有更好的发展。", "17761311498",
                contentDataList);
        FollowerContent followerContent2 = new FollowerContent(R.mipmap.home_page_headphoto, "四川邮电", "2天前", 212, "奉献力量，奉献绿色", "每年的3月12日是我国的植树节，其实这天是孙中山先生逝世的纪念日。孙中山先生从小就喜爱植树，在他的故居至今仍生长着一棵已满百岁的檀香山酸豆树。这是1883年，年仅只有18岁的孙中山，千里迢迢从美国檀香山带回幼苗亲手栽种的，在他的精心培育下终于成材。确定这一天为植树节，一是从植树的季节考虑；二是为了纪念孙中山先生一生提倡植树造林的功绩。", "17761311498",
                contentDataList2);
        mNeaybyContentList.add(followerContent);
        mNeaybyContentList.add(followerContent2);
        mNearbyContentMyRecyclerViewAdapter.notifyDataSetChanged();
    }


}
